Repository navigation
Conversation
| be.gemm_dense(out_w, nt, pf.p.hn, n, pf.logits_buf.addr(), vrows, 0)?; | ||
| be.gemm_dense(out_w, nt, pf.p.hn, n, pf.logits_buf.addr(), vrows, | ||
| if be.name() == "cuda" { crate::backend::BATCHED } else { 0 })?; | ||
| } |
There was a problem hiding this comment.
🟠 High · Correctness · 1 of 5
BATCHED is applied to the logits GEMM on CUDA regardless of verify mode, so plain prefill with many rows may take the few-row kernel. The logits GEMM now passes BATCHED whenever the backend is CUDA, not only during draft verification. A large plain-prefill batch with many vrows is then sent to the few-row int8 kernel, which is meant for a handful of rows. That can be much slower than the tile-list path, or incorrect if the kernel assumes a small row count.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 1118
Symbol: verify_forward
Issue: BATCHED is applied to the logits GEMM on CUDA regardless of verify mode, so plain prefill with many rows may take the few-row kernel. The logits GEMM now passes BATCHED whenever the backend is CUDA, not only during draft verification. A large plain-prefill batch with many vrows is then sent to the few-row int8 kernel, which is meant for a handful of rows. That can be much slower than the tile-list path, or incorrect if the kernel assumes a small row count.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| @@ -1211,6 +1215,7 @@ impl Device { | |||
| let be = &*d.parts[0].be; | |||
| let w = |x: &Mat| d.tensor(x.gpu.unwrap()); | |||
| let small = Self::small(be, nt, verify_mode); | |||
There was a problem hiding this comment.
🔵 Low · Maintainability · 2 of 5
Backend is identified by string comparison in device code instead of a capability query. Whether BATCHED is used depends on the literal string "cuda". A renamed or new CUDA-like backend silently falls back to the slow path. A backend with a different name that supports the kernel is never used. Changing the name would silently disable the optimisation everywhere.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 1217
Symbol: prefill_layer
Issue: Backend is identified by string comparison in device code instead of a capability query. Whether BATCHED is used depends on the literal string "cuda". A renamed or new CUDA-like backend silently falls back to the slow path. A backend with a different name that supports the kernel is never used. Changing the name would silently disable the optimisation everywhere.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| @@ -1211,6 +1215,7 @@ impl Device { | |||
| let be = &*d.parts[0].be; | |||
| let w = |x: &Mat| d.tensor(x.gpu.unwrap()); | |||
| let small = Self::small(be, nt, verify_mode); | |||
There was a problem hiding this comment.
🔵 Low · Maintainability · 3 of 5
The batched decision belongs in the launcher, which already sees nt and the shape, not in each caller. Every call site must remember to pass the right flag. The new flag is threaded through proj_n and pf_ffn_core, and it is easy to omit at a new call site, so that projection silently takes the slower kernel. The launcher could choose the few-row kernel itself from nt and the backend's capabilities.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 1217
Symbol: prefill_layer
Issue: The batched decision belongs in the launcher, which already sees nt and the shape, not in each caller. Every call site must remember to pass the right flag. The new flag is threaded through proj_n and pf_ffn_core, and it is easy to omit at a new call site, so that projection silently takes the slower kernel. The launcher could choose the few-row kernel itself from nt and the backend's capabilities.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| @@ -1340,7 +1345,7 @@ impl Device { | |||
| m.lap(0, t_prep); | |||
| let t_gpu = std::time::Instant::now(); | |||
| if fe.part == 0 { | |||
There was a problem hiding this comment.
🔵 Low · Maintainability · 4 of 5
Positional bool parameters are growing (batched added to pf_ffn_core with an allow(clippy::too_many_arguments)). pf_ffn_core now takes nine arguments, two of them bools whose meaning is set only by position. Callers can swap small, batched and use_gemm without a compile error. Deriving batched from verify_mode and small inside the callee, or bundling flags in a struct, would remove this risk.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 1347
Symbol: prefill_layer
Issue: Positional bool parameters are growing (batched added to pf_ffn_core with an allow(clippy::too_many_arguments)). pf_ffn_core now takes nine arguments, two of them bools whose meaning is set only by position. Callers can swap small, batched and use_gemm without a compile error. Deriving batched from verify_mode and small inside the callee, or bundling flags in a struct, would remove this risk.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| } | ||
| Self::pf_ffn_core(be1, m, ip, fe, pf1, nt, small, use_gemm)?; | ||
| Self::pf_ffn_core(be1, m, ip, fe, pf1, nt, small, batched, use_gemm)?; | ||
| let acc: Vec<f32> = be1.get(&pf1.acc_buf, 0, nt * n)?; |
There was a problem hiding this comment.
🔵 Low · Correctness · 5 of 5
batched is computed from device 0's backend (be) but reused for the be1 path. In the multi-device branch, pf_ffn_core runs on be1 with the batched value computed from be. If be1 is a different backend, or the name check differs between devices, the flag is wrong for that device, and its GEMMs take a kernel it does not support or skip one it could use.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 1363
Symbol: prefill_layer
Issue: batched is computed from device 0's backend (be) but reused for the be1 path. In the multi-device branch, pf_ffn_core runs on be1 with the batched value computed from be. If be1 is a different backend, or the name check differs between devices, the flag is wrong for that device, and its GEMMs take a kernel it does not support or skip one it could use.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
Aletheore Flash Lite reviewWhat this PR does. This pull request changes the CUDA verification path for the inkling2 model so that draft-token checks use a few-row batched int8 GEMM kernel instead of the tile-list prefill GEMM, by threading a new
5 finding(s) posted as inline review comment(s).
Review detailsReviewed 1 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 5 of 5 proposed finding(s). Fix all with your agent |
🔍 Aletheore evidence diffgraph LR
n0["device.rs"]
n1["forward.rs"]
n0 --> n1
classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
class n0 changed
class n1 dependent
What changed
Aggregate deltas
|
Inkling 2 verifies up to 16 draft rows per step, but its GEMMs used the prefill tile path, which decodes weights per tile. This marks verified-draft GEMMs (attention/router projections and the batched LM head) with
BATCHEDon CUDA so the launcher uses the existing few-row int8 kernel, which decodes weights once into MMA fragments — the same idea as llama.cpp's few-row MMQ for speculative verification, using this repo's existing kernel. Plain prefill, the matvec path (nt <= 6), Vulkan and HIP are unchanged.Verification
tests/inkling2_forward.rs4/4 andtests/kernels.rs::small_batch_gemm_matches_tile_gemmpass on CUDA.benchdecode 28.9 -> 35.0 tok/s at pp 512 and 31.5 -> 34.8 at pp 2048; teacher-forced top-1 493/510, mean KL 1.49e-2. This variation is run to run and is not caused by this change.I did not get any measurable throughput improvement from this change.